var express = require('express');
var jwt = require('jsonwebtoken');
var URL = require('url');
var router = express.Router();

router.get('/', function (req, res, next) {
    res.render("login", {title: "登录"});
});

// route to authenticate a user (POST http://localhost:8080/api/authenticate)
router.post('/', function (req, res) {
    //session中保存user
    var username = req.body.username;
    req.session.user = {'username':username};
    //重定向
    var redirect_url = req.body.redirect;
    if(redirect_url == ''){
       res.redirect('/')
    }else{
       res.redirect(redirect_url)
    }
});

module.exports = router;